import LangSwitcher from "@/components/lang-switcher";
import { mapActions, mapState } from "vuex";
import { SET_LANG } from "@/store/user/actionTypes";

export default {
  components: {
    LangSwitcher,
  },
  computed: {
    ...mapState("user", ["lang"]),
  },
  watch: {
    lang() {
      this.clearValidate();
    },
  },
  mounted() {
    this.setLang(JSON.parse(localStorage.getItem("lang")) || "zh-CN");
    this.clearValidate();
  },
  methods: {
    ...mapActions("user", [SET_LANG]),

    setLang(lang) {
      this[SET_LANG]({ lang });
      this.$i18n.locale = lang;
    },
    clearValidate() {
      if (this.submitForm) {
        setTimeout(() => {
          this.submitForm.clearValidate();
        }, 0);
      }
    },
  },
};
